<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<div id="myDiv"><h2 id="myh2">使用 AJAX 修改该文本内容</h2></div>
<button type="button" id="mybtn" >修改内容</button>
<script>
    $(function () {
        console.log("ok");
        //单击事件
        $("#mybtn").click(function () {
            var user ={id:1,name:"lisi"};
            $.ajax({
                url: '/json/test4',
                type: 'post',
                contentType: "application/json",//声明请求参数类型为 json
                data: JSON.stringify(user),//转换js对象成json
                success: function (user) {//成功回调函数
                    console.log(user);
                    $("#myh2").text(user.name);
                }
            });
        });
    });
</script>
</body>
</html>